package com.peng.leetcode.tree;

/**
 * InsertIntoMaxTree1
 *
 * @author: lupeng6
 * @create: 2023/2/19 15:43
 */
public class InsertIntoMaxTree1 {

    public static void main(String[] args) {
        TreeNode root = TreeMain.array2tree(new Integer[]{4, 1, 3, null, null, 2});
        TreeNode node = new InsertIntoMaxTree1().insertIntoMaxTree(root, 5);
        System.out.println(node);
    }

    public TreeNode insertIntoMaxTree(TreeNode root, int val) {
        if (root == null) {
            return new TreeNode(val);
        }
        if (root.val < val) {
            TreeNode node = new TreeNode(val);
            node.left = root;
            return node;
        }
        root.right = insertIntoMaxTree(root.right, val);
        return root;
    }
}
